<?php

class ClassCourseTagsController extends GxController {

    public function filters() {
        return array('rights');
    }

    public function actionView($id) {
        $this->render('view', array(
            'model' => $this->loadModel($id, 'ClassCourseTags'),
        ));
    }

    public function actionCreate() {
        $model = new ClassCourseTags;
        if (isset($_POST['ClassCourseTags'])) {
            $model->setAttributes($_POST['ClassCourseTags']);
            $model->create_time = SkillConfig::CreateDateTime();
            if ($model->save()) {
                if (Yii::app()->getRequest()->getIsAjaxRequest())
                    Yii::app()->end();
                else
                    $this->redirect(array('view', 'id' => $model->id));
            }
        }

        $this->render('create', array('model' => $model));
    }

    public function actionUpdate($id) {
        $model = $this->loadModel($id, 'ClassCourseTags');


        if (isset($_POST['ClassCourseTags'])) {
            $model->setAttributes($_POST['ClassCourseTags']);

            if ($model->save()) {
                $this->redirect(array('view', 'id' => $model->id));
            }
        }

        $this->render('update', array(
            'model' => $model,
        ));
    }

    public function actionDelete($id) {
        if (Yii::app()->getRequest()->getIsPostRequest()) {
            $this->loadModel($id, 'ClassCourseTags')->delete();

            if (!Yii::app()->getRequest()->getIsAjaxRequest())
                $this->redirect(array('admin'));
        } else
            throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
    }

    public function actionIndex() {
        $dataProvider = new CActiveDataProvider('ClassCourseTags');
        $this->render('index', array(
            'dataProvider' => $dataProvider,
        ));
    }

    public function actionAdmin() {
        $model = new ClassCourseTags('search');
        $model->unsetAttributes();
        $statuschangeurl = Yii::app()->createUrl('classCourseTags/statuschange/');
        if (isset($_GET['ClassCourseTags']))
            $model->setAttributes($_GET['ClassCourseTags']);

        $this->render('admin', array(
            'model' => $model,
            'statuschangeurl' => $statuschangeurl,
        ));
    }

    public function actionStatuschange() {
        $model = $this->loadModel($_POST['id'], 'ClassCourseTags');
        $model->status = $_POST['status'];
        $model->save();
    }

    public function actionsuggesttag($usersid,$type) {
        $dataProvider = new CActiveDataProvider('ClassCourseTags', array(
                    'criteria' => array(
                         'condition' => 'users_id=' . $usersid.' AND status='.SkillConfig::STATUS_DEACTIVE,
                    ),
                    'pagination' => array(
                        'pageSize' => 20,
                    ),
                ));
        $this->render('suggest_tag', array(
            'model' => $dataProvider, 'users_id' => $usersid,'type'=>  $type
        ));
    }

}
